package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo5 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException {
        Person p=new Person();
        p.say("你好");
        Class cls=Class.forName("reflect.Person");
        Object obj=cls.newInstance();
        Method m=cls.getMethod("say",String.class);
        m.invoke(obj,"大家好!");
        Method m1=cls.getMethod("say",String.class,int.class);
        m1.invoke(obj,"才是真的好!",5);
    }
}
